A. Technical Field
The invention in general relates to data processing systems and methods, and in particular to multithreaded data processing systems and methods.
B. Background of the Invention
In a multithreaded system, an application or process is subdivided into multiple threads. The central processing unit (CPU) switches rapidly between the different threads, and thus creates the illusion that the threads are running concurrently. Each thread typically has its own program counter, stack and thread state.
Threads often share resources such as memory space. To prevent inter-thread conflicts in accessing a shared resources, multithreaded systems employ mutexes, or mutual exclusion objects. A mutex is a shared resource that can be locked or unlocked. A thread locks a mutex, accesses data in the shared space, and unlocks the mutex when the need to access the shared space is over. A second thread must wait for the original thread to unlock the mutex before accessing the share space.
Threads also often need to communicate with one another. For example, one thread may be a consumer of data produced by another thread. The producer thread may need to signal the consumer thread when data is available for the consumer thread. Conversely, the consumer thread may need to signal to the producer thread that the consumer cannot accept any more data. Interthread communication can be achieved using condition variables. A condition variable is employed by a thread to make itself wait until some condition, which may depend on another thread, is met. For example, when a producer thread finds it cannot continue, e.g. if its output buffer is full, the producer thread executes a wait condition instruction and suspends execution. When the condition has been met, e.g. the producer's output buffer is no longer full, another process such as the consumer can wake up the producer thread by executing a signal instruction for the condition variable that the producer is waiting on.
Thread management functions such as mutex lock, wait condition and signal are multithreading system calls. Multithreading system calls are normally relatively complex procedures. In a conventional operating system running on a general-purpose CPU, a high-level language multithreading system call can be translated into a relatively large number (e.g. hundreds or thousands) of machine code instructions.